﻿#pragma once

//实现vtk渲染窗口的功能

#include <QDialog.h>
#include <QPushButton.h>
#include <QLineEdit>
#include <QDoubleSpinBox>
#include <QLabel.h>
#include <QWidget>
#include <QMessageBox>
#include <QBoxLayout>
#include <QGroupBox>

#include "QtVtkModleGlobalValue.h"
#include "MyVtkViewWindow.h"
#include "ActorManager.h"


//单例模式  
class DlgBase: public QDialog
{
public:
    DlgBase(QWidget* parent = nullptr);
    virtual ~DlgBase();//to be implemented(执行) by subclass

    virtual void initUI();
    virtual void manageConnections();

private:



};



//创建一个 int 编辑 组件QWidget
// 具备以下功能QDoubleSpinBox Qlabel
//可以设置标题文本
//可以设置默认值
//可以设置最小值
//可以设置最大值
//可以获取显示值
class MyDoubleEdit: public QWidget
{
    Q_OBJECT
public:
    MyDoubleEdit(QWidget* parent = nullptr, const QString& title = "",
                 double defaultValue = 0, double minValue = 0,
                 double maxValue = 100, int decimals = 6);
    ~MyDoubleEdit();

    void setValue(double value);
    double getValue() const;

    void setMinValue(double value);
    double getMinValue() const;

    void setMaxValue(double value);
    double getMaxValue() const;
    void setRange(double min, double max);

    void setDecimals(int decimals);
    int getDecimals() const;

    void setTitle(const QString& title);
    QString getTitle() const;


private:
    void initUI();
    void manageConnections();


private slots:
    void onValueChanged();

signals:
    void valueChanged(double value);


private:
    QDoubleSpinBox* m_lineEdit = nullptr;
    QLabel* m_label = nullptr;
    double m_minValue = 0;
    double m_maxValue = 0;
    double m_value = 0;
    QString m_title = "base dialog";
    QHBoxLayout* m_layout = nullptr;
};


//创建一个 组件QWidget
// 具备以下功能：
// 用于编辑3D 坐标点的x y z 值，用于编辑4d 坐标点的x y z w 值
//可以设置组件标题
//可以设置组件默认值
//可以获取显示值
//每个值都使用 MyDoubleEdit 组件编辑
class MyCoordinateEdit: public QGroupBox
{
    Q_OBJECT
public:
    MyCoordinateEdit(QWidget* parent = nullptr, const QString& title = "",
                     double defaultValue[4] = nullptr, bool if4D = false, int decimals = 2);

    ~MyCoordinateEdit();

    void setIf4D(bool if4D);
    void setValues(double x, double y, double z, double w = 1);
    void getValues(double& x, double& y, double& z, double& w) const;
    void getValues(double& x, double& y, double& z) const;

    void setDecimals(int decimals);


    MyDoubleEdit* getXEdit() const;
    MyDoubleEdit* getYEdit() const;
    MyDoubleEdit* getZEdit() const;
    MyDoubleEdit* getWEdit() const;


private:
    void initUI();
    void manageConnections();

private slots:
    void onValueChanged(double value);

signals:
    void valueChanged(double value);


private:
    bool m_if4D = false;
    MyDoubleEdit* m_xEdit = nullptr;
    MyDoubleEdit* m_yEdit = nullptr;
    MyDoubleEdit* m_zEdit = nullptr;
    MyDoubleEdit* m_wEdit = nullptr;

    QVBoxLayout* m_layout = nullptr;
};